#coding=utf-8
'''
Created on 2015年4月28日

@author:  emode
'''
from django.conf import settings
import datetime
import qiniu
import mimetypes
from qiniu import put_data, put_file, put_stream
from qiniu import BucketManager
#初始化七牛环境

ACCESS_KEY = settings.QINIU_ACCESS_KEY
SECRET_KEY = settings.QINIU_SECRET_KEY
BUCKET_NAME = settings.QINIU_BUCKET_NAME
#上传凭证
q = qiniu.Auth(ACCESS_KEY,SECRET_KEY)
# 上传策略仅指定空间名和上传后的文件名，其他参数仅为默认值
token = q.upload_token(BUCKET_NAME)
bucket = BucketManager(q)

# 得到token值
def get_uptoken(self):
    q = qiniu.Auth(ACCESS_KEY,SECRET_KEY)
    token = q.upload_token(BUCKET_NAME)
    return token

def get_file_info():
    ret, info = bucket.stat(BUCKET_NAME, ACCESS_KEY)
    print(info)

# s=get_uptoken(0)
# print "token的值为：%s",s
def upload_test():
    key ='你好'
    data = 'hello bubby!'
    ret, info = put_data(token, key, data)
    print 'info :%s',info
    assert ret['key'] == key
    
class SuperQiniu(object):
    def __init__(self, filepath, w=200, h=200, request=None, **kwargs):
        self.filepath = filepath    # 文件绝对路径
        self.key = datetime.datetime.now()               # 文件唯一标示
        self.request = request
        self.w = w      # 宽度
        self.h = h      # 高度
        self.kwargs = kwargs
     
    def upload_file(self):
      '''上传图片   '''  
        
    
# s = get_file_info()
# print 's:%s',s
upload_test()

